﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HROReporting.Model.PresentieIncheckingen;
using HROReporting.Model.Docenten;
using NHibernate;
using NHibernate.Criterion;
using HROReporting.Infrastructure.Querying;
using HROReporting.Infrastructure.UnitOfWork;

namespace HROReporting.Repository.NHibernate.Repositories
{
    public class PresentieIncheckingRepository : Repository<PresentieInchecking, int>, IPresentieIncheckingRepository
    {
        public PresentieIncheckingRepository(IUnitOfWork uow)
            : base(uow)
        {
        }


        public Boolean CheckIfStudentCheckingIn(string studentNumber)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(PresentieInchecking))
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<PresentieInchecking>
                (s => s.Studentnummer), studentNumber));

            IList<PresentieInchecking> students = criteriaQuery.List<PresentieInchecking>();

            if (students.Count <= 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public IEnumerable<Presentielijst> GetPresentielijstenBySerial(string serial)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(Presentielijst))
                .CreateAlias("NFCDevice", "NFCDevice")
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<Presentielijst>
                (d => d.NFCDevice.NFCDeviceSerial), serial));

            IList<Presentielijst> presentielijsten = criteriaQuery.List<Presentielijst>();

            return presentielijsten;
        }
    }
}
